<?php
/*
 *
 * 
 * 
 * AG 4/1/2012      Add comment to product page 
 */


// show off: template
require_once("configuration.php");
require_once("includes/io.php");
require_once("includes/template.php");
require_once("includes/category.php");
require_once("includes/product.php");
require_once("includes/function.php");
require_once("includes/function.number.php");


$id = (isset($_GET['id'])) ? intval(sql_injection($_GET['id'])) : 0;
$type= (isset($_GET['type'])) ? intval(sql_injection($_GET['type'])) : 0;
// check id is integer
if (is_int($id) && $id > 0) {
// initialization
    $template = new template("default");

// variable initializationu
    $categories = "";
    $product_rows = "";
    $menu_rows = "";


// Product section
    $news_object = new Product();
    $news_object->id = $id;
    if($type==-1)
        $news_object->getnews() ;
    else
        $news_object->get();

    if ($news_object->id > 0) {
        $category_id = $news_object->category_id;
        if ($news_object->discount > 0) {


            $discount_price = get_discount_price($news_object->price, $news_object->discount);
            $news_object->price = "<del>{$news_object->price}$</del> {$discount_price}$";
        } else {
            $news_object->price = $news_object->price . "$";
        }
    }
// Comment section
    require_once("includes/comment.php");
    $comment = new Comment();
    $query_comment = $comment->get_comments($id);
    while($obj = $mysql->fo($query_comment)){
        $comment = Comment::static_set_object($obj);
        eval("\$comment_object .= \"" . $template->get("comment") . "\";");
    }
    
// Categories section
    require_once("includes/list.categories.php");
    require_once("includes/cart.php");
    require_once("includes/list.cart.php");
// layout
    $title = "Home";
// Navigator
    require_once("includes/page.php");
    require_once("includes/list.menu.php");

    eval("\$content = \"" . $template->get("news.content") . "\";");
    
    eval("\$header = \"" . $template->get("header") . "\";");
    eval("\$cart = \"" . $template->get("body.cart") . "\";");
    eval("\$body = \"" . $template->get("body") . "\";");
    eval("\$footer = \"" . $template->get("footer") . "\";");
    eval("\$index = \"" . $template->get("index") . "\";");

// display all
    echo ($index); // can use echo $template->compress($index) to compress size of html

    require_once("configuration.end.php");
}
?>